package com.yuanlrc.base.controller.common;

import com.yuanlrc.base.service.common.MinioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@RestController
@RequestMapping("/minio")
public class MinioController {

    @Autowired
    private MinioService minioService;

    // 文件上传接口
    @PostMapping("/upload")
    public String uploadFile(@RequestParam("file") MultipartFile file) {
        try {
            minioService.uploadFile(file);
            return "文件上传成功!";
        } catch (Exception e) {
            return "上传失败: " + e.getMessage();
        }
    }

    // 文件下载接口
    @GetMapping("/download/{fileName}")
    public InputStream downloadFile(@PathVariable String fileName) {
        try {
            return minioService.downloadFile(fileName);
        } catch (Exception e) {
            throw new RuntimeException("下载失败: " + e.getMessage());
        }
    }
}

